package com.ruoyi.carShop.controller;

import com.ruoyi.carShop.domain.RegisterAndChange;
import com.ruoyi.carShop.service.RegisterService;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class RegisterController {
    @Autowired
    private RegisterService registerService;
    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("shopRegister1")
    public AjaxResult register(@RequestBody RegisterAndChange registerAndChange){
        //进行验证码的验证是否正确
       if( !registerAndChange.getCode().equals(redisTemplate.opsForValue().get(registerAndChange.getMobile()))){
           return AjaxResult.error("验证码错误");
       }
        String phone = registerAndChange.getMobile();
        int i = registerService.register(registerAndChange);
        if(i==0){
            return AjaxResult.error("注册失败");
        }
        redisTemplate.delete(registerAndChange.getMobile());
        return AjaxResult.success();
    }
}
